package com.piggy.logi.sys.controller;

import com.piggy.common.core.domain.R;
import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.Log;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.logi.sys.api.bo.LogiDeptLineEditBo;
import com.piggy.logi.sys.api.vo.LogiDeptLineExtVo;
import com.piggy.logi.sys.bo.LogiDeptLineQueryBo;
import com.piggy.logi.sys.service.ILogiDeptLineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 服务商常用线路管理Controller
 *
 * @author piggy
 * @date 2023-12-04
 */
@Api(value = "服务商常用线路管理控制器", tags = {"服务商常用线路管理管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/deptline")
public class LogiDeptLineController extends BaseController {

    private final ILogiDeptLineService iLogiDeptLineService;

    /**
     * 查询服务商常用线路管理列表
     */
    @ApiOperation("查询服务商常用线路管理列表")
    //@SaCheckPermission("sys:line:list")
    @PostMapping("/list")
    public TableDataInfo<LogiDeptLineExtVo> list(@Validated @RequestBody LogiDeptLineQueryBo bo) {
        return iLogiDeptLineService.queryPageList(bo);
    }

    /**
     * 导出服务商常用线路管理列表
     */
    @ApiOperation("导出服务商常用线路管理列表")
    //@SaCheckPermission("sys:line:export")
    @Log(title = "服务商常用线路管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated LogiDeptLineQueryBo bo, HttpServletResponse response) throws IOException {
        List<LogiDeptLineExtVo> list = iLogiDeptLineService.queryList(bo);
        ExcelUtil<LogiDeptLineExtVo> util = new ExcelUtil<>(LogiDeptLineExtVo.class);
        util.exportExcel(response, list, "服务商常用线路管理");
    }

    /**
     * 获取服务商常用线路管理详细信息
     */
    @ApiOperation("获取服务商常用线路管理详细信息")
    //@SaCheckPermission("sys:line:query")
    @GetMapping("/{id}")
    public R<LogiDeptLineExtVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iLogiDeptLineService.queryById(id));
    }

    /**
     * 新增服务商常用线路管理
     */
    @ApiOperation("新增服务商常用线路管理")
    //@SaCheckPermission("sys:line:add")
    @Log(title = "服务商常用线路管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<LogiDeptLineExtVo> add(@Validated @RequestBody LogiDeptLineEditBo bo) {
        return R.ok(iLogiDeptLineService.insertByAddBo(bo));
    }

    /**
     * 修改服务商常用线路管理
     */
    @ApiOperation("修改服务商常用线路管理")
    //@SaCheckPermission("sys:line:edit")
    @Log(title = "服务商常用线路管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<LogiDeptLineExtVo> edit(@Validated @RequestBody LogiDeptLineEditBo bo) {
        return R.ok(iLogiDeptLineService.updateByEditBo(bo));
    }

    /**
     * 删除服务商常用线路管理
     */
    @ApiOperation("删除服务商常用线路管理")
    //@SaCheckPermission("sys:line:remove")
    @Log(title = "服务商常用线路管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Integer> remove(@NotEmpty(message = "主键不能为空")
                             @PathVariable Long[] ids) {
        return R.ok(iLogiDeptLineService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
